// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/connectors/hive/iceberg/iceberg_split.h>

#include <pollux/connectors/hive/iceberg/iceberg_delete_file.h>

namespace kumo::pollux::connector::hive::iceberg {

HiveIcebergSplit::HiveIcebergSplit(
    const std::string& connectorId,
    const std::string& filePath,
    dwio::common::FileFormat fileFormat,
    uint64_t start,
    uint64_t length,
    const std::unordered_map<std::string, std::optional<std::string>>&
        partitionKeys,
    std::optional<int32_t> tableBucketNumber,
    const std::unordered_map<std::string, std::string>& customSplitInfo,
    const std::shared_ptr<std::string>& extraFileInfo,
    bool cacheable,
    const std::unordered_map<std::string, std::string>& infoColumns,
    std::optional<FileProperties> properties)
    : HiveConnectorSplit(
          connectorId,
          filePath,
          fileFormat,
          start,
          length,
          partitionKeys,
          tableBucketNumber,
          customSplitInfo,
          extraFileInfo,
          /*serdeParameters=*/{},
          /*storageParameters=*/{},
          /*splitWeight=*/0,
          cacheable,
          infoColumns,
          properties,
          std::nullopt,
          std::nullopt) {
  // TODO: Deserialize _extraFileInfo to get deleteFiles;
}

// For tests only
HiveIcebergSplit::HiveIcebergSplit(
    const std::string& connectorId,
    const std::string& filePath,
    dwio::common::FileFormat fileFormat,
    uint64_t start,
    uint64_t length,
    const std::unordered_map<std::string, std::optional<std::string>>&
        partitionKeys,
    std::optional<int32_t> tableBucketNumber,
    const std::unordered_map<std::string, std::string>& customSplitInfo,
    const std::shared_ptr<std::string>& extraFileInfo,
    bool cacheable,
    std::vector<IcebergDeleteFile> deletes,
    const std::unordered_map<std::string, std::string>& infoColumns,
    std::optional<FileProperties> properties)
    : HiveConnectorSplit(
          connectorId,
          filePath,
          fileFormat,
          start,
          length,
          partitionKeys,
          tableBucketNumber,
          customSplitInfo,
          extraFileInfo,
          /*serdeParameters=*/{},
          /*storageParameters=*/{},
          0,
          cacheable,
          infoColumns,
          properties,
          std::nullopt,
          std::nullopt),
      deleteFiles(std::move(deletes)) {}
} // namespace kumo::pollux::connector::hive::iceberg
